from django.shortcuts import render
from django.http import HttpResponseRedirect
from .models import Feedback
from django.urls import reverse
from .forms import FeedbackForm
import mistune
from django.contrib.auth.decorators import login_required

@login_required
def index(request):
	feedback_form = FeedbackForm()
	context = {'feedback_form':feedback_form}
	return render(request, "feedback/index.html", context=context)

def process(request):
	new_feedback = Feedback()
	new_feedback.feedback_body = request.POST['feedback_body']
	new_feedback.user_name = request.user.username
	new_feedback.title = request.POST['feedback_title']
	render_md = mistune.create_markdown(plugins=['strikethrough', 'table'])
	markdown_html = render_md(new_feedback.feedback_body)
	new_feedback.html_text = markdown_html
	new_feedback.save()
	return HttpResponseRedirect(reverse("home:index"))

def look_all(request):
	all_feedback = Feedback.objects.all()
	context = {'all': all_feedback}
	return render(request, "feedback/look.html", context=context)